package com.quick.domain;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @ClassName MailQueue
 * @Description 单例，邮件队列
 * @Author Wangxin
 * @Date 2019-03-02 21:29
 * @Version 1.0
 **/
public class MailQueue {
    public static BlockingQueue<Mail> mailBlockingQueue = new ArrayBlockingQueue<>(1000);

    private volatile static MailQueue mailQueue;
    private MailQueue(){}

    public static MailQueue getInstance(){
        if (null==mailQueue){
            synchronized (MailQueue.class){
                if (null==mailQueue){
                    mailQueue = new MailQueue();
                }
            }
        }
        return mailQueue;
    }

    public void put(Mail mail) throws Exception{
        mailBlockingQueue.put(mail);
    }

    public Mail take() throws Exception{
        return mailBlockingQueue.take();
    }

    public int size(){
        return mailBlockingQueue.size();
    }
}
